package com.evil.kingdom.controller.skill;

import com.evil.common.core.entity.R;
import com.evil.kingdom.pojo.entity.person.skill.Skill;
import com.evil.kingdom.service.skill.SkillService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 技能
 *
 * @author liyang
 * @date 2024-05-22 17:11
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/skill")
public class SkillController {

    private final SkillService skillService;

    /**
     * 初始化技能
     *
     * @return R
     */
    @RequestMapping("/init")
    public R<String> init(String suffix) {
        skillService.init(suffix);
        return R.success();
    }

    /**
     * 新增技能
     *
     * @param skill skill
     * @return R
     */
    @PostMapping("/add")
    public R<Skill> add(@RequestBody @Validated Skill skill) {
        return R.success(skillService.add(skill));
    }

    /**
     * 更新技能
     *
     * @param skill skill
     * @return R
     */
    @PostMapping("/update")
    public R<Skill> update(@RequestBody @Validated Skill skill) {
        return R.success(skillService.update(skill));
    }

    /**
     * 查询技能
     *
     * @param name name
     * @return R
     */
    @RequestMapping("/find-by-name")
    public R<Skill> findByName(String name) {
        return R.success(skillService.findByName(name));
    }
}
